//
//  DUSystemWindowController.swift
//  SimpleCal
//
//  Created by 杜晓祥 on 2021/10/29.
//

import Cocoa

class DUSystemWindowController: NSWindowController, NSWindowDelegate {
    
    @IBOutlet weak var mView: NSView!
//
//
//    @IBOutlet weak var mainView: NSView!
//    private var holidayController:DUTypeManagerController!
//
    private var manager = DUHolidayController()
    override var windowNibName: NSNib.Name? {
      return "DUSystemWindowController"
    }
    
    override func windowDidLoad() {
        super.windowDidLoad()
        self.window?.center()
        self.window?.makeKeyAndOrderFront(nil)
        NSApplication.shared.activate(ignoringOtherApps: true)
        self.window?.isRestorable = false
//        holidayController = DUTypeManagerController()
        //mainView.addSubview(.view)
        mView.addSubview(manager.view)
        //print(self.window?.frame)
       // NSApplication
//        let d1 = DUClipView()
//        d1.documentView = calBox
//        scrollView.contentView = d1
//        

        
        
        //let b1 = NSImage(named: "addIcon")!
        //let b2 = NSImage(named: "addIcon_click")!
        
        //let tbtn = DUImageButton(frame: NSMakeRect(5, 5, 48, 48), btnImage: b1, mouseImage: b2)
        //test.addSubview(tbtn)
        
//        var n:Int = 1
//        for i in (0...5) {
//            for j in (0...6) {
//                let x = CGFloat(j*30+5)
//                let y = CGFloat((5-i)*30+5)
//                let b = DUDayButton(frame: NSMakeRect(x, y, 30, 30), solarValue: "\(n)",
//                                    lunarValue: CalendarUtil.LUNAR_TEST_DAY_TO_STRING[n])
//                n += 1
//                radio.addSubview(b)
//                b.action = #selector(buttonHandler(_ :))
//                testView.addSubview(b)
//            }
//        }
        
    }

    func mask () {
        let v = DUMaskView(frame: NSMakeRect(0, 0, 720, 510))
        let b = DUButton(frame: NSMakeRect(50, 50, 200, 200))
        b.stringValue("测试按钮", data: 1)
        v.addSubview(b)
//        mView.addSubview(v)
    }
    
    @objc func testbutton (_ sender: Any?) {
        print("----------")
    }

    @IBAction func save(_ sender: Any) {
        let s = CalendarUtil.getNowDate()
        print(CalendarUtil.solarToLunar(solar: s))
    }
    
    @IBAction func query(_ sender: Any) {
        let typeDao = BaseDao<TypeEntity>()
        print(typeDao.query(format: ""))
    }
    
    func windowWillClose(_ notification: Notification) {
        NSApplication.shared.terminate(self)
    }
    
    

}
